package kotlinquanweizhinan.chapt4函数.nyetHack

class Games {

}

fun main(args:Array<String>) {
    val name = "Madrigal"
    val healthPoints = 10
    val isBlessed = true
    val isImmortal = false
    val auraColor = auraColor(isBlessed, healthPoints, isImmortal)
    val healthStatus = formatHeathStatus(healthPoints, isBlessed)
    val fireballStatus = castFireball()
    printPlayerStatus(auraColor, isBlessed, name, healthStatus)



    //传入值参
    printPlayerStatus("NONE",true,"Madrigal","status")
    //具名函数值参
    printPlayerStatus(healthStatus = "status",
    auraColor = "NONE",
    name="Madrigal",
    isBlessed = true)
}



private fun auraColor1(isBlessed: Boolean, healthPoints: Int, isImmortal: Boolean): String {
    val auraVisible = isBlessed && healthPoints > 50 || isImmortal
    val auraColor = if (auraVisible) "GREEN" else "NONE"
    return auraColor
}

private fun auraColor(isBlessed: Boolean, healthPoints: Int, isImmortal: Boolean)=
    if(isBlessed && healthPoints > 50 || isImmortal)
    { "GREEN"}
    else{"NONE"}




//private fun formatHeathStatus(healthPoints: Int, isBlessed: Boolean): String {
//    val healthStatus2 = when (healthPoints) {
//        100 -> "is in excellent conditin!"
//        in 90..99 -> "has a few scratches."
//        in 75..89 -> if (isBlessed) {
//            "has some minor wounds but is healing quite quickly!(受了点伤，但恢复极快！)"
//        } else {
//            "has some minor wounds.(小伤口)"
//        }
//        in 15..74 -> "pretty hurt.!(受伤严重)"
//        else -> "is in awful condition!"
//    }
//    return healthStatus2
//}

//单表达式函数
private fun formatHeathStatus(healthPoints: Int,isBlessed: Boolean)=
     when (healthPoints) {
        100 -> "is in excellent conditin!"
        in 90..99 -> "has a few scratches."
        in 75..89 -> if (isBlessed) {
            "has some minor wounds but is healing quite quickly!(受了点伤，但恢复极快！)"
        } else {
            "has some minor wounds.(小伤口)"
        }
        in 15..74 -> "pretty hurt.!(受伤严重)"
        else -> "is in awful condition!"
}

private fun printPlayerStatus(auraColor: String, isBlessed: Boolean, name: String, healthStatus: String) {
    println(
        "(Aura:$auraColor)" +
                "(Blessed: ${if(isBlessed) "YES" else "NO"})"
    )
    println("$name $healthStatus")

}

//private fun castFireball()
//{
//    println("A glass of Fireball springs into existence.")
//}

//private fun castFireball(numFireballs:Int){
//    println("A glass of Fireball springs into existence.(x$numFireballs)")
//}


//单表达式函数
private fun castFireball1(numFireballs: Int=2)=
        println("A glass of Fireball springs into existence.(x$numFireballs)")

private fun castFireball(numFireballs: Int=2)=
        when(numFireballs){
            in 1..10 -> "tipsy"
            in 11..20 ->"sloshed(微醉)"
            in 21..30 ->"soused"
            in 31..40 -> "stewed(大醉)"
            else -> "烂醉如泥"
        }



